<?php
include("../include/db.php");
include("includes/thumbnail.php");

$_SESSION['rpage'] = $_SERVER['REQUEST_URI']; 
if(!isset($_SESSION[$prefix."_username"])){header("location:../login/");exit;}
if ($_SESSION[$prefix."_security"] < 10){header("location:../login/?error=2"); exit;}

$year = date("Y");
$date = "03/18/2011";


if ($_SERVER['REQUEST_METHOD'] == "POST") { 
	
	$film		= $_POST[film];
	$venue		= $_POST[venue];
	$date		= $_POST[date];
	$hour		= $_POST[hour];
	$min		= $_POST[min];
	$ampm		= $_POST[ampm];

if($venue != 'none' && $film != 'none'){
	if($ampm == 'pm'){$hour = $hour + 12;}
	$time = "00:".$hour.":".$min;
	
	$date = date("Y-m-d", strtotime($date));

	//************************ INSERT INTO COURSES_TRM ********************************  
	$query = "INSERT INTO screenings 
				(film_id,
				date,
				time,
				venue_id,
				type)
			 VALUES (
			 	'$id',
			 	'$date',
			 	'$time',
			 	'$venue',
			 	'f'
			 )";
	$result = mysql_query($query, $db) or die(mysql_error());
	//********************************************************************************* 
}


	
header("Location: schedule.php?action=added"); exit; 
}//END POST
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="includes/admin.css"/>
<title><?php echo $global_title;?></title>

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js"></script>
<script type="text/javascript" src="../../ckeditor/ckeditor.js"></script>
<link rel="stylesheet" type="text/css" href="includes/jqueryui.css">
<script> 
	$(function() {
		$( "#date" ).datepicker();
	});
	</script> 
	
</head>
<body>

<div id="wrap">
	<div id="page-header">
		<?php include('includes/header.php');?>

	</div>
	
	<div id="page-body">
		<div id="tabs">
			<?php $tab="main"; include('includes/header_tabs.php');?>
		</div>

		<div id="acp">
		<div class="panel">
			<span class="corners-top"><span></span></span>
				<div id="content">
				<div id="menu">
						
					<?php include('includes/menu_top.php');?>	
					<?php include('includes/menu_main.php');?>
					</div>
	
					<div id="main">
<a name="maincontent"></a>


	<h1>Add Screening</h1>

	<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1" >
	
		
 		<fieldset><legend>Add Screening</legend> 
			
			<dl>
				<dt>Film:</dt>
			
				<dd>
				<select name="film" id="film">
                    <option value="none">None</option>
                    
                    <?php
                    
                    $result = mysql_query("SELECT * FROM films WHERE film_id > 0 ORDER BY title", $db);
                    	while ($myrow2 = mysql_fetch_array($result, MYSQL_ASSOC)) { ?>
                    	<option value="<?php echo $myrow2["film_id"];?>" <?php if($myrow2["film_id"] == $in_film){echo "selected";}?>><?php echo $myrow2["title"];?></option>

                    	<?php }?>

                  </select>
                 </dd>
               </dl>  
			
			<dl>
				<dt>Venue:</dt>
			
				<dd>
				<select name="venue" id="venue">
                    <option value="none">None</option>
                    
                    <?php
                    
                    $result = mysql_query("SELECT * FROM venues  ORDER BY venue_name", $db);
                    	while ($myrow2 = mysql_fetch_array($result, MYSQL_ASSOC)) { ?>
                    	<option value="<?php echo $myrow2["venue_id"];?>" <?php if($myrow2["venue_id"] == $in_venue){echo "selected";}?>><?php echo $myrow2["venue_name"];?></option>

                    	<?php }?>

                  </select>
                 </dd>
               </dl>  
                  
          <dl>
            <dt>Date:</dt>
            <dd><input type="date" name="date" id="date" value="<?php echo $date;?>"   /></dd>
          </dl>
          
          <dl>
            <dt>Time:</dt>
            <dd><input type="number" name="hour" id="hour" step="1" min="1" max="12" placeholder="hour" size="4" maxlength="2" /> :
            	<input type="number" name="min" id="min" step="1" min="0" max="60" placeholder="min" size="4" maxlength="2"   />
            	<select name="ampm" id="ampm" >
            		<option value="am">AM</option>
            		<option value="pm" selected >PM</option>
            	</select>
            	</dd>
          </dl>	
         
      <p class="submit-buttons"><input type="submit" class="button1" name="submit" id="submit" value="Submit" /></p>
</fieldset>
    </form>	
		


    
		</div><!-- main -->
	</div><!-- content -->
<span class="corners-bottom"><span></span></span>
</div><!-- panel -->
</div><!-- acp -->

	
	<div id="page-footer">
	<?php include('includes/footer.php');?>
				</div>
</div><!-- page-body -->
</div><!-- wrap -->

   <script type="text/javascript">
	CKEDITOR.replace( 'editor1', {toolbar : 'MyToolbar'} );
	
	CKEDITOR.config.width = '700';
	CKEDITOR.config.height = '200';
	CKEDITOR.config.toolbarStartupExpanded = 'false';
	
</script>

</body> 
</html>